home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’89 / Dialoger / Utils.c < prev   
Encoding:
C/C++ Source or Header  |  1989-06-16  |  2.7 KB  |  108 lines  |  [TEXT/KAHL]

  1. /* ================================================================ */
  2. /*                            Utilities                                 */
  3. /* ---------------------------------------------------------------- */
  4.  
  5. #define    maxStrings    30
  6.  
  7. extern char        letterArray[5];    
  8. extern Boolean    hasEditFields;
  9.  
  10. isoptionkey()
  11. {
  12.     return(iskeydown(58));
  13. };
  14.     
  15. iskeydown(keycode)
  16. int    keycode;
  17. {
  18.     /* returns true if the key specified in the map by
  19.         keycode is down false otherwise */
  20.         
  21.     KeyMap    thekeys;
  22.     long    mask;
  23.     int        bank;
  24.     int        temp;
  25.         
  26.     GetKeys(&thekeys);    /* check what keys are down -- Option is 58 */
  27.     
  28.     bank = keycode / 32;        /* get the right bank to use */
  29.     temp = (keycode % 32);         /* ok now get the byte .... */
  30.     
  31.     temp = ((temp / 8 ) * 8 ) + ( 7 - (temp % 8));
  32.     
  33.     mask = 1L << ( 31 - temp);
  34.     if (( thekeys.Key[bank] & mask ) == 0 )
  35.         return(0);
  36.     else
  37.         return(1);
  38. };
  39.  
  40. /* ================================================================ */
  41. void FlashItem(theDialog, theItem)
  42. register DialogPtr theDialog;
  43. register int   theItem;
  44. /* ---------------------------------------------------------------- */
  45. {
  46.     int        theKind;
  47.     Handle    theHandle;
  48.     Rect    theRect;
  49.     long    dummy;
  50.     
  51.     GetDItem(theDialog, theItem, &theKind, &theHandle, &theRect);
  52.     HiliteControl(theHandle, 1);    /* Turn it on */
  53.     Delay(8L, &dummy);
  54.     HiliteControl(theHandle, 0);    /* Turn it off */
  55.     
  56. }
  57.  
  58. /* ================================================================ */
  59. void WalkList(theDialog)
  60. register DialogPtr theDialog;
  61. /* ---------------------------------------------------------------- */
  62. {
  63.     int        theKind, itemCount, theItem=1, counter=1;
  64.     Handle    theHandle;
  65.     Rect    theRect;
  66.     Str255    theString;
  67.     
  68.     BlockMove(*(((DialogPeek)theDialog)->items), &itemCount, sizeof(int));
  69.     do
  70.     {
  71.         GetDItem(theDialog, theItem, &theKind, &theHandle, &theRect);
  72.         if (theKind==(ctrlItem+btnCtrl)) /* should not be rads or checks in alert */
  73.         {
  74.             GetCTitle(theHandle, &theString);
  75.             if ((IUCompString(theString,"\pCancel")==0) || 
  76.                 (IUCompString(theString,"\pCANCEL")==0))
  77.                 letterArray[counter] = '.'; /* default to . */
  78.             else
  79.             {
  80.                 if ((theString[1]>0x40) && (theString[1]<0x60))
  81.                     theString[1] = theString[1]+0x20;
  82.                 letterArray[counter] = theString[1]; /*get the first char - and mask case*/
  83.             }
  84.         }
  85.         else if ((theKind==editText+itemDisable) || 
  86.                  (theKind==editText))
  87.         {
  88.             hasEditFields = TRUE;    /* it helps to set this flag */
  89.             letterArray[counter] = '';    /* NOTHING */
  90.         }
  91.         else
  92.         {
  93.             letterArray[counter] = '';    /* NOTHING */
  94.         }
  95.         if (counter==5)
  96.         {
  97.             GetCTitle(theHandle, &theString);
  98.             if (IUCompString(theString,"\pEject")==0)    /*must be StdFile*/
  99.                 hasEditFields = TRUE;
  100.         }
  101.         counter++;
  102.         if (counter>maxStrings)    {theItem=itemCount+1;}
  103.         theItem++;    /* it would help to increment the item# */
  104.     } while (theItem<=itemCount);
  105.     
  106. }
  107.  
  108.